{% extends 'base_templates/_page_layout.html' %}
{% load staticfiles %}
{% load authentication_tags %}
{% block css %}
    <link href="/static/plugins/minton/plugins/summernote/summernote-bs4.css" rel="stylesheet" />

    <link href="/static/plugins/minton/plugins/switchery/switchery.min.css" rel="stylesheet" />
    <link href="/static/plugins/minton/plugins/jquery-circliful/css/jquery.circliful.css" rel="stylesheet" type="text/css" />
    <!--Footable-->
    <link href="/static/plugins/minton/plugins/footable/css/footable.core.css" rel="stylesheet">
    <!-- DataTables -->
    <link href="/static/plugins/minton/plugins/datatables/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css">
    <link href="/static/plugins/minton/plugins/datatables/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css">

    <!-- Responsive datatable examples -->
    <link href="/static/plugins/minton/plugins/datatables/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css">
    <style>
        
        #divAdvancedFeatures {
            position: fixed;
            /*width:10px;*/
            /*height:10px;*/
            /*border:1px solid red;*/
            right:0px;
            /*top:0px;*/
            z-index:100;
        }
        .side-bar.right-bar {
            float: right !important;
            right: -266px;
            top: 230px;
            bottom: 0;
            font-size: 0.9rem;
        }
        .right-bar {
            background: #0000 !important;
            z-index: 99 !important;
        }
        .cancel-border {
            box-shadow: 0 0 8px 0px rgba(0, 0, 0, 0);
        }
        
        #lcons_label{
            text-align: center; /*让div内部文字居中*/
            /*background-color: #fff;*/
            /*border-radius: 20px;*/
            /*width: 300px;*/
            /*height: 350px;*/
            /*margin: auto;*/
            /*position: absolute;*/
            top: 19%;
            /*left: 0;*/
            /*right: 0;*/
            /*bottom: 0;*/
        }
        .btn-sm {
            text-align: center;
            padding: .5rem .35rem;
            font-size: 0.875rem;
            line-height: 0.5;
            border-radius: 0.2rem;
        }

        .widget-bg-color-icon .bg-icon {
            height: 34px;
            width: 34px;
            /* text-align: center; */
            border-radius: 50%;
        }

        .widget-bg-color-icon .bg-icon i {
            font-size: 24px;
            color: #ffffff !important;
            line-height: 23px;
        }

        #TrackResume {
            cursor:pointer;
        }

        .label_level {
            margin-top: -3px;
            margin-right: 10px;
            margin-bottom: 15px;
        }
    </style>
    <!-- Dropzone css -->
    <link href="/static/plugins/minton/plugins/dropzone/dropzone.css" rel="stylesheet">
    <link href="/static/css/dropzone_custom_update_file.css" rel="stylesheet" type="text/css">
    

{% endblock %}

{% block title %}

    <!-- Page-Title -->
<div class="row">
    <div class="col-sm-12">
        <div class="page-title-box">
            <h4 class="page-title">候选人信息</h4>
            <ol class="breadcrumb float-right">
                <li class="breadcrumb-item"><a href="/resume/candidate/{{obj.id}}/change">{{obj.username}}</a></li>
                <li class="breadcrumb-item"><a href="/resume/list">侯选人列表</a></li>
                <li class="breadcrumb-item active">Dashboard</li>
            </ol>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{% endblock %}

{% block conent %}
    {% include 'include/_resume_detailed_information.html' %}
    {% include 'include/Models/_upload_resume_onefile_parsing.html' %}


<div id="ViewsJS" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="full-width-modalLabel" style="display: none;" aria-hidden="true">
    <div class="modal-dialog modal-full">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="full-width-modalLabel">附件内容</h4>
            </div>
            <div class="modal-body">
                <iframe id="iframe_viewerjs" name="zh_filename" src="" width="100%" height="780px" allowfullscreen="" webkitallowfullscreen=""></iframe>
            </div>
            <div class="modal-footer">
                {# <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Close</button> #}
                {# <button type="button" class="btn btn-primary waves-effect waves-light">Save changes</button> #}
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
{% endblock %}

{% block sidebar %} 
    {% include 'include/_resume_info_right_side_menu.html' %}
{% endblock %}

{% block js %}
<script src="/static/plugins/minton/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/minton/plugins/datatables/dataTables.bootstrap4.min.js"></script>
<!-- Dropzone js -->
<script src="/static/plugins/minton/plugins/dropzone/dropzone.js"></script>
<script src="/static/js/dropzone_custom_update_onefile.js"></script>

<!--form summernote-->
<script src="/static/plugins/minton/plugins/summernote/summernote-bs4.min.js"></script>
<script>
    // 评论框
    jQuery(document).ready(function(){

        $('.summernote').summernote({
            height: 350,                 // set editor height
            minHeight: null,             // set minimum height of editor
            maxHeight: null,             // set maximum height of editor
            focus: false                 // set focus to editable area after initializing summernote
        });

        $('.inline-editor').summernote({
            airMode: true
        });

    });
</script>
<script>
    current_resume_info_id = "{{ uid }}"
    update_file_type = "zh_filename"

    $(function () {
        btnDelete();
        ResumeSubscription();
        SetFileType();
        PageTop();
        ExportWorkDocument();
        RightSidebar();
        TrackResume();
    });

    // 自定义 右侧 菜单
    function RightSidebar(){
        $("#btnAdvancedFeatures").click(function(){
            var wrapper = document.getElementById('wrapper');
            if (wrapper.getAttribute("class")=='right-bar-enabled'){
                $("#wrapper").removeClass("right-bar-enabled");
            }else{
                $("#wrapper").addClass("right-bar-enabled");
            }
        })
    }
    //  置顶
    function PageTop(){
        $("#btnPageTop").click(function(){
            document.documentElement.scrollTop = 0;
        })
    }

    // 导出 Word 文件
    function ExportWorkDocument(){
        $("#btnExportWord").click(function(){
            $.ajax({
                url: '/documents/export/word/'+ '{{ uid }}',
                type: "GET",
                success:function (arg) {
                    if (arg.status_code == "200"){
                        window.location="/documents/download/word?file="+arg.file_path+"&token=" + arg.token; 
                    }else{
                        swal({
                            title: '错误的导出',
                            text: arg.describe,
                            type: 'error',
                            confirmButtonClass: 'btn btn-confirm mt-2'
                        })
                    }
                }
            })
        })
    }

    // 设置上传文件的类型，后续决定是否解析
    function SetFileType(){
        $('#zh_filename').click(function () {
            update_file_type = "zh_filename";
        });
        $('#en_filename').click(function () {
            update_file_type = "en_filename";
        });
    }

    // 删除当前简历
    function btnDelete() {
        $("#btnDelete").click(function () {
            //Warning Message
            swal({
                title: '确定删除?',
                text: "确定删除此信息?",
                type: 'warning',
                showCancelButton: true,
                confirmButtonClass: 'btn btn-confirm mt-2 slzccDelete',
                cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(function () {
                swal({
                    title: '删除 !',
                    text: "已经删除此信息",
                    type: 'success',
                    confirmButtonClass: 'btn btn-confirm mt-2'
                    }
                )
            });
            $('.slzccDelete').click(function () {
                $.ajax({
                    url: "/resume/candidate/delete/{{ uid }}",
                    type: "POST",
                    dataType: "JSON",
                    success: function (arg) {
                        window.location.href="/resume/list";
                    }
                })
            });
        });
    }


</script>
<script>
    // 收藏订阅
    function ResumeSubscription(){
        $("#btnResumeSubscription").click(function(){
            var subscribe = $("#btnResumeSubscription").attr("status")
            if (subscribe == "subscribe"){
                $.ajax({
                    url: '/resume/candidate/subscription',
                    type: "POST",
                    data: {"sub_obj": {{ uid }}},
                    dataType: "JSON",
                    success:function (arg) {
                        if(arg.status_code == 200 && arg.event == "subscribe"){
                            $("#btnResumeSubscription").removeClass("btn-primary");
                            $("#btnResumeSubscription").addClass("btn-warning");
                            $("#btnResumeSubscription").text("取消收藏");
                            $("#btnResumeSubscription").attr("status", "unsubscribe");
                            swal({
                                title: '收藏成功',
                                text: "您以收藏此份简历成功!",
                                type: 'success',
                                confirmButtonClass: 'btn btn-confirm mt-2'
                            }).then(function () {
                            });
                        }
                    }
                });
            }else{
                $.ajax({
                    url: '/resume/candidate/subscription',
                    type: "POST",
                    data: {"sub_obj": {{ uid }}, "unsubscribe": "True"},
                    dataType: "JSON",
                    success:function (arg) {
                        if(arg.status_code == 200 && arg.event == "unsubscribe"){
                            $("#btnResumeSubscription").removeClass("btn-warning");
                            $("#btnResumeSubscription").addClass("btn-primary");
                            $("#btnResumeSubscription").text("收藏简历");
                            $("#btnResumeSubscription").attr("status", "subscribe");
                            swal({
                                title: '取消收藏',
                                text: "您以取消此份简历的收藏!",
                                type: 'info',
                                confirmButtonClass: 'btn btn-confirm mt-2'
                            }).then(function () {
                            });
                        }
                    }
                });
            }
        })
    };
</script>
<script>

    // 评论
    !function($) {
        "use strict";

        var ChatApp = function() {
            this.$body = $("body"),
            this.$chatInput = $('.chat-input'),
            this.$chatList = $('.inbox-widget'),
            this.$chatSendBtn = $('.chat-send .btn')
        };

        //saves chat entry - You should send ajax call to server in order to save chat enrty
        ChatApp.prototype.save = function() {
            var chatText = this.$chatInput.val();
            // var chatTime = moment().format("YYYY MMMM Do h:mm:ss");
            // var chatTime = moment().format('YYYY-MM-DD h:mm:ss');
            var chatTime = moment().format('YY/M/D hh:mm:ss');
            if (chatText == "") {
                sweetAlert("Oops...", "You forgot to enter your chat message", "error");
                this.$chatInput.focus();
            } else {
                $('<div class="inbox-item"><div class="inbox-item-img"><img src="{% static request.user.head_portrait %}" class="rounded-circle" alt=""></div><p class="inbox-item-author">{{ request.user.name }}</p><p class="inbox-item-text"><pre>'+ chatText + '</pre></p><p class="inbox-item-date">' + chatTime + '</p></div><hr>').appendTo('.inbox-widget');
                this.$chatInput.val('');
                this.$chatInput.focus();
                var data = {};
                data["user_id"] = "{{ request.user.id }}";
                data["resume_id"] = "{{ uid }}";
                data["describe"] = chatText;
                // data["create_time"] = chatTime;
                SaveResumeCommands(data);
            }
        },
        ChatApp.prototype.init = function () {
            var $this = this;
            //binding keypress event on chat input box - on enter we are adding the chat into chat list - 
            $this.$chatInput.keypress(function (ev) {
                var p = ev.which;
                if (p == 13) {
                    $this.save();
                    return false;
                }
            });


            //binding send button click
            $this.$chatSendBtn.click(function (ev) {
               $this.save();
               return false;
            });
        },
        //init ChatApp
        $.ChatApp = new ChatApp, $.ChatApp.Constructor = ChatApp
        
    }(window.jQuery),

    //initializing main application module
    function($) {
        "use strict";
        $.ChatApp.init();
    }(window.jQuery);

    function SaveResumeCommands(postData){
        $.ajax({
            url: '/resume/candidate/commands/save',
            data: postData,
            type: 'POST',
            dataType: 'JSON',
            success: function(arg){
                // console.log(arg)
            }
        })
    }
</script>
<script>
    
    // 生成 PDF
    $("#btnViewsJS").click(function(){
        var attachmentName = document.getElementById("attachmentName").value;

        var getData = {'attachmentName': attachmentName};
        swal({
            title: '正在加载中 PDF',
            // type: 'info',
            html: '如果你不需要加载 PDF，则可以取消.</br>'+
            '</br>'+
            '<img src="/static/system/5-121204194109.gif" size="100px" style=""> ',
            showCloseButton: true,
            showCancelButton: false,
            // confirmButtonClass: 'btn btn-cancel ml-2 mt-2',
            confirmButtonClass: 'btn btn-danger mt-2 btn-pdf',
            cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
            // confirmButtonText: '<i class="fa fa-thumbs-up"></i> Great!',
            cancelButtonText: '<i class="fa fa-thumbs-down"></i>',
            confirmButtonText: '取消!',
            allowOutsideClick: false
        })

        $.ajax({
            url: "/source/checkPDF",
            type: 'GET',
            data: getData,
            dataType: "JSON",
            success: function(arg){
                
                // console.log(arg.pdfFileName);
                $("#iframe_viewerjs").attr("src", "/ViewerJS/index.html/#" + arg.targetFileUrl);
                $(".btn-pdf").click();
                var documentName = decodeURI($("div #documentName").text())
                $("div #documentName").text(documentName)
            }
        })
    });

</script>
<script>
// // 自适应 textarea
// $(function(){
//     $.fn.autoHeight = function(){    
//         function autoHeight(elem){
//             elem.style.height = 'auto';
//             elem.scrollTop = 0;
//             elem.style.height = elem.scrollHeight + 'px';
//         }this.each(function(){
//             autoHeight(this);
//             $(this).on('keyup', function(){
//                 autoHeight(this);
//             });
//         }); 
//     }
// })
</script>
<!-- Counter Up  -->
<script src="/static/plugins/minton/plugins/waypoints/lib/jquery.waypoints.min.js"></script>
<script src="/static/plugins/minton/plugins/counterup/jquery.counterup.min.js"></script>

<!-- circliful Chart -->
<script src="/static/plugins/minton/plugins/jquery-circliful/js/jquery.circliful.min.js"></script>
<script src="/static/plugins/minton/plugins/jquery-sparkline/jquery.sparkline.min.js"></script>

<!-- skycons -->
<script src="/static/plugins/minton/plugins/skyicons/skycons.min.js" type="text/javascript"></script>

<!-- Page js  -->
<script src="/static/plugins/minton/pages/jquery.dashboard.js"></script>
<!--FooTable-->
<script src="/static/plugins/minton/plugins/footable/js/footable.all.min.js"></script>
<!--FooTable Example-->
<script src="/static/plugins/minton/pages/jquery.footable.js"></script>
<script>
    jQuery(document).ready(function($) {
        $('.counter').counterUp({
            delay: 100,
            time: 1200
        });
        $('.circliful-chart').circliful();
    });

    // BEGIN SVG WEATHER ICON
    if (typeof Skycons !== 'undefined'){
        var icons = new Skycons(
                {"color": "#3bafda"},
                {"resizeClear": true}
                ),
                list  = [
                    "clear-day", "clear-night", "partly-cloudy-day",
                    "partly-cloudy-night", "cloudy", "rain", "sleet", "snow", "wind",
                    "fog"
                ],
                i;

        for(i = list.length; i--; )
            icons.set(list[i], list[i]);
        icons.play();
    };

</script>
<script>
     // 关联
    function TrackResume(){
        $("#TrackResume").click(function(){
            var status = $("#TrackResume").attr("status")
            var location = $("#TrackResume").attr("location")
            var owner = $("#TrackResume").attr("owner")
            

            if (status == "Cancel"){
                if (location != owner){
                    swal({
                        title: '错误',
                        text: "此简历已被 " + owner + " 追踪，请联系后进行解决!",
                        type: 'error',
                        confirmButtonClass: 'btn btn-confirm mt-2'
                    })
                }else{
                    var postData = {"id": "{{ obj.id }}", "CancelTrack": "True", "location": location, "owner": owner}
                    //Warning Message
                    swal({
                        title: '取消追踪',
                        text: "确定取消追踪此份简历?",
                        type: 'info',
                        showCancelButton: true,
                        confirmButtonClass: 'btn btn-confirm mt-2 track_resume',
                        cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
                        confirmButtonText: '确定',
                        cancelButtonText: '取消'
                    }).then(function () {
                        $.ajax({
                            url: '/resume/candidate/track',
                            data: postData,
                            type: 'POST',
                            dataType: "JSON",
                            success: function(arg){
                                if (arg.status_code != "200"){
                                    swal({
                                        title: '取消失败',
                                        text: arg.describe,
                                        type: 'error',
                                        confirmButtonClass: 'btn btn-confirm mt-2'
                                    })
                                }else{
                                    swal({
                                        title: '取消追踪成功',
                                        text: arg.describe,
                                        type: 'success',
                                        confirmButtonClass: 'btn btn-confirm mt-2'
                                    }).then(function () {
                                        window.location.reload()
                                    });
                                    
                                }
                            }
                        })
                    });
                }

            }else{
                if (! location == owner || ! owner == "None"){
                    swal({
                        title: '错误',
                        text: "此简历已被 " + owner + " 追踪，请联系后进行解决!",
                        type: 'error',
                        confirmButtonClass: 'btn btn-confirm mt-2'
                    })
                }else{

                    var postData = {"id": "{{ obj.id }}", "CancelTrack": "False", "location": location, "owner": owner}
                    //Warning Message
                    swal({
                        title: '追踪简历',
                        text: "确定追踪此份简历?",
                        type: 'info',
                        showCancelButton: true,
                        confirmButtonClass: 'btn btn-confirm mt-2 track_resume',
                        cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
                        confirmButtonText: '确定',
                        cancelButtonText: '取消'
                    }).then(function () {
                        $.ajax({
                            url: '/resume/candidate/track',
                            data: postData,
                            type: 'POST',
                            dataType: "JSON",
                            success: function(arg){
                                if(arg.status_code == "403"){
                                    swal({
                                        title: '追踪失败',
                                        text: arg.describe,
                                        type: 'error',
                                        confirmButtonClass: 'btn btn-confirm mt-2'
                                    })
                                }else if(arg.status_code != "200"){
                                    swal({
                                        title: '追踪失败',
                                        text: arg.describe,
                                        type: 'error',
                                        confirmButtonClass: 'btn btn-confirm mt-2'
                                    })
                                }else{
                                    swal({
                                        title: '追踪成功',
                                        text: arg.describe,
                                        type: 'success',
                                        confirmButtonClass: 'btn btn-confirm mt-2'
                                    }).then(function () {
                                        window.location.reload()
                                    });
                                }
                            }
                        })
                    });
                }
            }
        })
    }
</script>
{% endblock %}